Practice Lab 7.1 – Business rules

Scenario

You are a Power Platform functional consultant and have been assigned to the Fabrikam project for the next stage of the project.

In this practice lab, you will be creating business rules to show and hide the lookup columns in the model-driven app form for the Resource table and to set the status of Milestone rows to completed when the percentage complete is 100%. You will also create a low-code plug-in to validate dates.

Exercise 1 – Create business rules

Task 1.1 – Create Resource business rules

  1. Navigate to the Power Apps Maker portal https://make.powerapps.com

  2. Make sure you are in the Dev One environment.

  3. Select Solutions.

  4. Open the Fabrikam Environmental solution.

  5. In the Objects pane on the left, expand Tables.

  6. Select the Resource table.

  7. Under Customizations, select Business rules.

  8. Select the existing business rule, Set Resource Name, to open the business rule designer. Analyze how this business rule works. This business rule controls the visibility and requirement for the resource name based on the selection of resource type.

  9. Close the Business rule designer.

  10. Select Done.

  11. Select + New business rule from the command bar.

  12. In the Business rule designer, next to the New business rule name at the top of the screen, select the drop-down caret.

  13. Enter Resource Type Internal for Business rule name. You can select on the drop-down caret again to collapse this section.

  14. In the Scope drop-down in the top-right of the Business rules designer, select All Forms.

  15. Select the Condition tile in the canvas and in the Properties pane enter Check Resource Type for Display Name.

  16. In the Rules section, select Resource Type for Field, select Equals for Operator, select Value for Type, and select Internal for Value.

  17. Select Apply.

  18. Select the Components tab.

  19. Drag the Set Visibility action and place it on the True side (on the right-hand side) of the condition.

  20. Enter Show User for Display Name.

  21. In the Visibility section, select User and Yes.

  22. Select Apply.

  23. Drag another Set Visibility action from the Components tab and place it on the right-hand side of the Show User tile.

  24. Enter Hide Contact for Display Name. In the Visibility section, select Contact and No.

  25. Select Apply.

  26. Select + Add and select Add Set Business Required and then select the plus icon to the right of the Hide Contact tile.

  27. Enter User Required for Display Name. In the Business Required section, select User and Business Required.

  28. Select Apply.

  29. Select + Add and select Add Set Business Required and then select the plus icon to the right of the User Required tile.

  30. Enter Contact Not Required for Display Name. In the Business Required section, select Contact and Not Business Required.

    New business rule.

  31. The Business Rule (Text View) should read as follows:

     IF
      Resource Type equals "Internal"
     THEN
      Show field User
      Hide field Contact
      Set User as Business Required
      Set Contact as Not Business Required
    
  32. Select Save. You should see the message Validation successful.

  33. Select Activate.

  34. In the Process Activate Confirmation dialog, select Activate.

  35. Select Save As.

  36. Next to Copy of Resource Type Internal name at the top of the screen, select the drop-down caret.

  37. Enter Resource Type External for Business rule name. Collapse the top section.

  38. Select the Check Resource Type tile.

  39. In the Rules section, uncheck Internal and check External.

  40. Select Apply.

  41. Select the Show User tile.

  42. Enter Hide User for Display Name. Select User, No in the Visibility section and select Apply.

  43. Select the Hide Contact tile.

  44. Enter Show Contact for Display Name. Select Contact, Yes in the Visibility section and select Apply.

  45. Select the User Required tile.

  46. Enter User Not Required for Display Name, select Not Business Required in the Business Required section and select Apply.

  47. Select the Contact Not Required tile.

  48. Enter Contact Required for Display Name, select Business Required for Status and select Apply.

  49. The Business Rule (Text View) should read as follows:

     IF
      Resource Type equals "External"
     THEN
      Hide field User
      Show field Contact
      Set User as Not Business Required
      Set Contact as Business Required
    
  50. Select Save. You should see the message that Validation was successful.

  51. Select Activate.

  52. In the Process Activate Confirmation dialog, select Activate.

  53. Close the business rule designer tab.

  54. Select Done.

Task 1.2 – Create Milestone business rules

  1. In the Objects pane on the left, select the Milestone table.

  2. Under Customizations, select Business rules.

  3. Select + New business rule.

  4. Next to New business rule name at the top of the screen, select the drop-down caret.

  5. Enter Milestone Completed for Business rule name. Collapse the top section.

  6. In the Scope drop-down in the top-right of the business rules designer, select Entity.

  7. Select the Condition tile in the canvas and in the Properties pane, enter Percentage Complete for Display Name.

  8. In the Rules section, select Milestone Percentage Complete for Field, select Equals for Operator, select Value for Type, and enter 100 for Value.

  9. At the top of the Rules section, select + New to add Rule 2.

  10. In the Rule 2 section, select Milestone Status for Field, select Does not equal for Operator, select Value for Type, and check Completed and Cancelled for Value.

  11. Select AND for Rule Logic.

  12. Select Apply.

  13. The Condition Expression (Text View) should read as follows:

     Milestone Percentage Complete equals 100 AND Milestone Status does not equal "Completed,Cancelled"
    
  14. Select + Add and select Add Set Field Value and then select the plus icon to the right of the Condition tile.

  15. Enter Mark Complete for Display Name. In the Field Value section, select Milestone Status for Field, select Value for Type, and select Completed for Value.

  16. Select Apply.

  17. The Business Rule (Text View) should read as follows:

     IF
      Milestone Percentage Complete equals 100 AND Milestone Status does not equal "Completed,Cancelled"
     THEN
      Set Milestone Status to "Completed"
    
  18. Select Save. You should see the message that Validation was successful.

  19. Select Activate.

  20. In the Process Activate Confirmation dialog, select Activate.

  21. Close the business rule designer tab.

  22. Select Done.

Exercise 2 – Low code plug-in

Task 2.1 – Create a low-code plug-in

  1. Navigate to the Power Apps Maker portal https://make.powerapps.com

  2. Make sure you are in the Dev One environment.

  3. Select Apps.

  4. Select All

  5. Select the Dataverse Accelerator App and select Play.

  6. Select + New plug-in and select Automated plug-in.

  7. Enter Project date validation for Display name.

  8. Select contoso_project for Table.

  9. Select Updated for Run this plug-in when the row is.

  10. Expand Advanced options.

  11. Select Pre-operation for When should this run.

  12. Select Fabrikam Environmental for Solution.

  13. Enter the following Expression.

     If(NewRecord.'Scheduled Start' > NewRecord.'Scheduled End', 
      Error({Kind: ErrorKind.Validation, Message: "The start date cannot be after the end date" })
     );
    

    Low-code plug-in.

  14. Select Save.

Challenge (Optional)

Edit the Set Resource Name business rule on the Resource table to hide both lookup columns if resource type is not selected and set as not business required.